package org.example.service.delay;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @author Tang
 * @classname DelayConsumer
 * @description [  ]
 * @date 2023/4/14 08:58
 */
//@RabbitListener(queues = {"email.queue"})
//@Component
public class Consumer {

    @RabbitHandler
    public void consumer(String msg, @Headers Map<String, Object> headers, Channel channel) {
        System.out.println("consumer-Receive: " + msg);
        Long deliveryTag  = (Long)headers.get(AmqpHeaders.DELIVERY_TAG);
        try {
//            channel.basicAck(deliveryTag,false);
            channel.basicNack(deliveryTag,false,false);
            System.out.println("丢弃消息: " + msg + "，deliveryTag：" + deliveryTag);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
